/*!
 * v-viewer v3.0.11
 * https://github.com/mirari/v-viewer#readme
 *
 * Copyright 2022 mirari
 * Released under the MIT license
 *
 * Date: 2022-10-25T08:49:33.301Z
 */
import Viewer from 'viewerjs'
export { default as Viewer } from 'viewerjs'
import {
  h,
  render,
  watch,
  nextTick,
  defineComponent,
  ref,
  onMounted,
  onUnmounted,
  openBlock,
  createElementBlock,
  renderSlot,
} from 'vue'
var commonjsGlobal =
  typeof globalThis !== 'undefined'
    ? globalThis
    : typeof window !== 'undefined'
    ? window
    : typeof global !== 'undefined'
    ? global
    : typeof self !== 'undefined'
    ? self
    : {}
function identity$2(value) {
  return value
}
var identity_1 = identity$2
function apply$1(func, thisArg, args) {
  switch (args.length) {
    case 0:
      return func.call(thisArg)
    case 1:
      return func.call(thisArg, args[0])
    case 2:
      return func.call(thisArg, args[0], args[1])
    case 3:
      return func.call(thisArg, args[0], args[1], args[2])
  }
  return func.apply(thisArg, args)
}
var _apply = apply$1
var apply = _apply
var nativeMax$1 = Math.max
function overRest$1(func, start, transform) {
  start = nativeMax$1(start === void 0 ? func.length - 1 : start, 0)
  return function () {
    var args = arguments,
      index2 = -1,
      length = nativeMax$1(args.length - start, 0),
      array = Array(length)
    while (++index2 < length) {
      array[index2] = args[start + index2]
    }
    index2 = -1
    var otherArgs = Array(start + 1)
    while (++index2 < start) {
      otherArgs[index2] = args[index2]
    }
    otherArgs[start] = transform(array)
    return apply(func, this, otherArgs)
  }
}
var _overRest = overRest$1
function constant$1(value) {
  return function () {
    return value
  }
}
var constant_1 = constant$1
var freeGlobal$1 =
  typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal
var _freeGlobal = freeGlobal$1
var freeGlobal = _freeGlobal
var freeSelf = typeof self == 'object' && self && self.Object === Object && self
var root$3 = freeGlobal || freeSelf || Function('return this')()
var _root = root$3
var root$2 = _root
var Symbol$3 = root$2.Symbol
var _Symbol = Symbol$3
var Symbol$2 = _Symbol
var objectProto$7 = Object.prototype
var hasOwnProperty$5 = objectProto$7.hasOwnProperty
var nativeObjectToString$1 = objectProto$7.toString
var symToStringTag$1 = Symbol$2 ? Symbol$2.toStringTag : void 0
function getRawTag$1(value) {
  var isOwn = hasOwnProperty$5.call(value, symToStringTag$1),
    tag = value[symToStringTag$1]
  try {
    value[symToStringTag$1] = void 0
    var unmasked = true
  } catch (e) {}
  var result = nativeObjectToString$1.call(value)
  if (unmasked) {
    if (isOwn) {
      value[symToStringTag$1] = tag
    } else {
      delete value[symToStringTag$1]
    }
  }
  return result
}
var _getRawTag = getRawTag$1
var objectProto$6 = Object.prototype
var nativeObjectToString = objectProto$6.toString
function objectToString$1(value) {
  return nativeObjectToString.call(value)
}
var _objectToString = objectToString$1
var Symbol$1 = _Symbol,
  getRawTag = _getRawTag,
  objectToString = _objectToString
var nullTag = '[object Null]',
  undefinedTag = '[object Undefined]'
var symToStringTag = Symbol$1 ? Symbol$1.toStringTag : void 0
function baseGetTag$4(value) {
  if (value == null) {
    return value === void 0 ? undefinedTag : nullTag
  }
  return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value)
}
var _baseGetTag = baseGetTag$4
function isObject$7(value) {
  var type = typeof value
  return value != null && (type == 'object' || type == 'function')
}
var isObject_1 = isObject$7
var baseGetTag$3 = _baseGetTag,
  isObject$6 = isObject_1
var asyncTag = '[object AsyncFunction]',
  funcTag$1 = '[object Function]',
  genTag = '[object GeneratorFunction]',
  proxyTag = '[object Proxy]'
function isFunction$2(value) {
  if (!isObject$6(value)) {
    return false
  }
  var tag = baseGetTag$3(value)
  return tag == funcTag$1 || tag == genTag || tag == asyncTag || tag == proxyTag
}
var isFunction_1 = isFunction$2
var root$1 = _root
var coreJsData$1 = root$1['__core-js_shared__']
var _coreJsData = coreJsData$1
var coreJsData = _coreJsData
var maskSrcKey = (function () {
  var uid = /[^.]+$/.exec((coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO) || '')
  return uid ? 'Symbol(src)_1.' + uid : ''
})()
function isMasked$1(func) {
  return !!maskSrcKey && maskSrcKey in func
}
var _isMasked = isMasked$1
var funcProto$1 = Function.prototype
var funcToString$1 = funcProto$1.toString
function toSource$1(func) {
  if (func != null) {
    try {
      return funcToString$1.call(func)
    } catch (e) {}
    try {
      return func + ''
    } catch (e) {}
  }
  return ''
}
var _toSource = toSource$1
var isFunction$1 = isFunction_1,
  isMasked = _isMasked,
  isObject$5 = isObject_1,
  toSource = _toSource
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g
var reIsHostCtor = /^\[object .+?Constructor\]$/
var funcProto = Function.prototype,
  objectProto$5 = Object.prototype
var funcToString = funcProto.toString
var hasOwnProperty$4 = objectProto$5.hasOwnProperty
var reIsNative = RegExp(
  '^' +
    funcToString
      .call(hasOwnProperty$4)
      .replace(reRegExpChar, '\\$&')
      .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') +
    '$'
)
function baseIsNative$1(value) {
  if (!isObject$5(value) || isMasked(value)) {
    return false
  }
  var pattern = isFunction$1(value) ? reIsNative : reIsHostCtor
  return pattern.test(toSource(value))
}
var _baseIsNative = baseIsNative$1
function getValue$1(object, key) {
  return object == null ? void 0 : object[key]
}
var _getValue = getValue$1
var baseIsNative = _baseIsNative,
  getValue = _getValue
function getNative$1(object, key) {
  var value = getValue(object, key)
  return baseIsNative(value) ? value : void 0
}
var _getNative = getNative$1
var getNative = _getNative
var defineProperty$1 = (function () {
  try {
    var func = getNative(Object, 'defineProperty')
    func({}, '', {})
    return func
  } catch (e) {}
})()
var _defineProperty = defineProperty$1
var constant = constant_1,
  defineProperty = _defineProperty,
  identity$1 = identity_1
var baseSetToString$1 = !defineProperty
  ? identity$1
  : function (func, string) {
      return defineProperty(func, 'toString', {
        configurable: true,
        enumerable: false,
        value: constant(string),
        writable: true,
      })
    }
var _baseSetToString = baseSetToString$1
var HOT_COUNT = 800,
  HOT_SPAN = 16
var nativeNow = Date.now
function shortOut$1(func) {
  var count = 0,
    lastCalled = 0
  return function () {
    var stamp = nativeNow(),
      remaining = HOT_SPAN - (stamp - lastCalled)
    lastCalled = stamp
    if (remaining > 0) {
      if (++count >= HOT_COUNT) {
        return arguments[0]
      }
    } else {
      count = 0
    }
    return func.apply(void 0, arguments)
  }
}
var _shortOut = shortOut$1
var baseSetToString = _baseSetToString,
  shortOut = _shortOut
var setToString$1 = shortOut(baseSetToString)
var _setToString = setToString$1
var identity = identity_1,
  overRest = _overRest,
  setToString = _setToString
function baseRest$1(func, start) {
  return setToString(overRest(func, start, identity), func + '')
}
var _baseRest = baseRest$1
function eq$2(value, other) {
  return value === other || (value !== value && other !== other)
}
var eq_1 = eq$2
var MAX_SAFE_INTEGER$1 = 9007199254740991
function isLength$2(value) {
  return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER$1
}
var isLength_1 = isLength$2
var isFunction = isFunction_1,
  isLength$1 = isLength_1
function isArrayLike$2(value) {
  return value != null && isLength$1(value.length) && !isFunction(value)
}
var isArrayLike_1 = isArrayLike$2
var MAX_SAFE_INTEGER = 9007199254740991
var reIsUint = /^(?:0|[1-9]\d*)$/
function isIndex$2(value, length) {
  var type = typeof value
  length = length == null ? MAX_SAFE_INTEGER : length
  return (
    !!length &&
    (type == 'number' || (type != 'symbol' && reIsUint.test(value))) &&
    value > -1 &&
    value % 1 == 0 &&
    value < length
  )
}
var _isIndex = isIndex$2
var eq$1 = eq_1,
  isArrayLike$1 = isArrayLike_1,
  isIndex$1 = _isIndex,
  isObject$4 = isObject_1
function isIterateeCall$1(value, index2, object) {
  if (!isObject$4(object)) {
    return false
  }
  var type = typeof index2
  if (
    type == 'number' ? isArrayLike$1(object) && isIndex$1(index2, object.length) : type == 'string' && index2 in object
  ) {
    return eq$1(object[index2], value)
  }
  return false
}
var _isIterateeCall = isIterateeCall$1
function baseTimes$1(n, iteratee) {
  var index2 = -1,
    result = Array(n)
  while (++index2 < n) {
    result[index2] = iteratee(index2)
  }
  return result
}
var _baseTimes = baseTimes$1
function isObjectLike$4(value) {
  return value != null && typeof value == 'object'
}
var isObjectLike_1 = isObjectLike$4
var baseGetTag$2 = _baseGetTag,
  isObjectLike$3 = isObjectLike_1
var argsTag$1 = '[object Arguments]'
function baseIsArguments$1(value) {
  return isObjectLike$3(value) && baseGetTag$2(value) == argsTag$1
}
var _baseIsArguments = baseIsArguments$1
var baseIsArguments = _baseIsArguments,
  isObjectLike$2 = isObjectLike_1
var objectProto$4 = Object.prototype
var hasOwnProperty$3 = objectProto$4.hasOwnProperty
var propertyIsEnumerable = objectProto$4.propertyIsEnumerable
var isArguments$1 = baseIsArguments(
  (function () {
    return arguments
  })()
)
  ? baseIsArguments
  : function (value) {
      return (
        isObjectLike$2(value) && hasOwnProperty$3.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee')
      )
    }
var isArguments_1 = isArguments$1
var isArray$1 = Array.isArray
var isArray_1 = isArray$1
var isBuffer$1 = { exports: {} }
function stubFalse() {
  return false
}
var stubFalse_1 = stubFalse
;(function (module, exports) {
  var root2 = _root,
    stubFalse2 = stubFalse_1
  var freeExports = exports && !exports.nodeType && exports
  var freeModule = freeExports && true && module && !module.nodeType && module
  var moduleExports = freeModule && freeModule.exports === freeExports
  var Buffer = moduleExports ? root2.Buffer : void 0
  var nativeIsBuffer = Buffer ? Buffer.isBuffer : void 0
  var isBuffer2 = nativeIsBuffer || stubFalse2
  module.exports = isBuffer2
})(isBuffer$1, isBuffer$1.exports)
var baseGetTag$1 = _baseGetTag,
  isLength = isLength_1,
  isObjectLike$1 = isObjectLike_1
var argsTag = '[object Arguments]',
  arrayTag = '[object Array]',
  boolTag = '[object Boolean]',
  dateTag = '[object Date]',
  errorTag = '[object Error]',
  funcTag = '[object Function]',
  mapTag = '[object Map]',
  numberTag = '[object Number]',
  objectTag = '[object Object]',
  regexpTag = '[object RegExp]',
  setTag = '[object Set]',
  stringTag = '[object String]',
  weakMapTag = '[object WeakMap]'
var arrayBufferTag = '[object ArrayBuffer]',
  dataViewTag = '[object DataView]',
  float32Tag = '[object Float32Array]',
  float64Tag = '[object Float64Array]',
  int8Tag = '[object Int8Array]',
  int16Tag = '[object Int16Array]',
  int32Tag = '[object Int32Array]',
  uint8Tag = '[object Uint8Array]',
  uint8ClampedTag = '[object Uint8ClampedArray]',
  uint16Tag = '[object Uint16Array]',
  uint32Tag = '[object Uint32Array]'
var typedArrayTags = {}
typedArrayTags[float32Tag] =
  typedArrayTags[float64Tag] =
  typedArrayTags[int8Tag] =
  typedArrayTags[int16Tag] =
  typedArrayTags[int32Tag] =
  typedArrayTags[uint8Tag] =
  typedArrayTags[uint8ClampedTag] =
  typedArrayTags[uint16Tag] =
  typedArrayTags[uint32Tag] =
    true
typedArrayTags[argsTag] =
  typedArrayTags[arrayTag] =
  typedArrayTags[arrayBufferTag] =
  typedArrayTags[boolTag] =
  typedArrayTags[dataViewTag] =
  typedArrayTags[dateTag] =
  typedArrayTags[errorTag] =
  typedArrayTags[funcTag] =
  typedArrayTags[mapTag] =
  typedArrayTags[numberTag] =
  typedArrayTags[objectTag] =
  typedArrayTags[regexpTag] =
  typedArrayTags[setTag] =
  typedArrayTags[stringTag] =
  typedArrayTags[weakMapTag] =
    false
function baseIsTypedArray$1(value) {
  return isObjectLike$1(value) && isLength(value.length) && !!typedArrayTags[baseGetTag$1(value)]
}
var _baseIsTypedArray = baseIsTypedArray$1
function baseUnary$1(func) {
  return function (value) {
    return func(value)
  }
}
var _baseUnary = baseUnary$1
var _nodeUtil = { exports: {} }
;(function (module, exports) {
  var freeGlobal2 = _freeGlobal
  var freeExports = exports && !exports.nodeType && exports
  var freeModule = freeExports && true && module && !module.nodeType && module
  var moduleExports = freeModule && freeModule.exports === freeExports
  var freeProcess = moduleExports && freeGlobal2.process
  var nodeUtil2 = (function () {
    try {
      var types = freeModule && freeModule.require && freeModule.require('util').types
      if (types) {
        return types
      }
      return freeProcess && freeProcess.binding && freeProcess.binding('util')
    } catch (e) {}
  })()
  module.exports = nodeUtil2
})(_nodeUtil, _nodeUtil.exports)
var baseIsTypedArray = _baseIsTypedArray,
  baseUnary = _baseUnary,
  nodeUtil = _nodeUtil.exports
var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray
var isTypedArray$1 = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray
var isTypedArray_1 = isTypedArray$1
var baseTimes = _baseTimes,
  isArguments = isArguments_1,
  isArray = isArray_1,
  isBuffer = isBuffer$1.exports,
  isIndex = _isIndex,
  isTypedArray = isTypedArray_1
var objectProto$3 = Object.prototype
var hasOwnProperty$2 = objectProto$3.hasOwnProperty
function arrayLikeKeys$1(value, inherited) {
  var isArr = isArray(value),
    isArg = !isArr && isArguments(value),
    isBuff = !isArr && !isArg && isBuffer(value),
    isType = !isArr && !isArg && !isBuff && isTypedArray(value),
    skipIndexes = isArr || isArg || isBuff || isType,
    result = skipIndexes ? baseTimes(value.length, String) : [],
    length = result.length
  for (var key in value) {
    if (
      (inherited || hasOwnProperty$2.call(value, key)) &&
      !(
        skipIndexes &&
        (key == 'length' ||
          (isBuff && (key == 'offset' || key == 'parent')) ||
          (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
          isIndex(key, length))
      )
    ) {
      result.push(key)
    }
  }
  return result
}
var _arrayLikeKeys = arrayLikeKeys$1
var objectProto$2 = Object.prototype
function isPrototype$1(value) {
  var Ctor = value && value.constructor,
    proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto$2
  return value === proto
}
var _isPrototype = isPrototype$1
function nativeKeysIn$1(object) {
  var result = []
  if (object != null) {
    for (var key in Object(object)) {
      result.push(key)
    }
  }
  return result
}
var _nativeKeysIn = nativeKeysIn$1
var isObject$3 = isObject_1,
  isPrototype = _isPrototype,
  nativeKeysIn = _nativeKeysIn
var objectProto$1 = Object.prototype
var hasOwnProperty$1 = objectProto$1.hasOwnProperty
function baseKeysIn$1(object) {
  if (!isObject$3(object)) {
    return nativeKeysIn(object)
  }
  var isProto = isPrototype(object),
    result = []
  for (var key in object) {
    if (!(key == 'constructor' && (isProto || !hasOwnProperty$1.call(object, key)))) {
      result.push(key)
    }
  }
  return result
}
var _baseKeysIn = baseKeysIn$1
var arrayLikeKeys = _arrayLikeKeys,
  baseKeysIn = _baseKeysIn,
  isArrayLike = isArrayLike_1
function keysIn$1(object) {
  return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object)
}
var keysIn_1 = keysIn$1
var baseRest = _baseRest,
  eq = eq_1,
  isIterateeCall = _isIterateeCall,
  keysIn = keysIn_1
var objectProto = Object.prototype
var hasOwnProperty = objectProto.hasOwnProperty
var defaults = baseRest(function (object, sources) {
  object = Object(object)
  var index2 = -1
  var length = sources.length
  var guard = length > 2 ? sources[2] : void 0
  if (guard && isIterateeCall(sources[0], sources[1], guard)) {
    length = 1
  }
  while (++index2 < length) {
    var source = sources[index2]
    var props = keysIn(source)
    var propsIndex = -1
    var propsLength = props.length
    while (++propsIndex < propsLength) {
      var key = props[propsIndex]
      var value = object[key]
      if (value === void 0 || (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) {
        object[key] = source[key]
      }
    }
  }
  return object
})
var defaults_1 = defaults
const inBrowser = typeof window !== 'undefined' && window !== null
checkIntersectionObserver()
const isEnumerable = Object.prototype.propertyIsEnumerable
const getSymbols = Object.getOwnPropertySymbols
function isObject$2(val) {
  return typeof val === 'function' || toString.call(val) === '[object Object]'
}
function isPrimitive(val) {
  return typeof val === 'object' ? val === null : typeof val !== 'function'
}
function isValidKey(key) {
  return key !== '__proto__' && key !== 'constructor' && key !== 'prototype'
}
function checkIntersectionObserver() {
  if (
    inBrowser &&
    'IntersectionObserver' in window &&
    'IntersectionObserverEntry' in window &&
    'intersectionRatio' in window.IntersectionObserverEntry.prototype
  ) {
    if (!('isIntersecting' in window.IntersectionObserverEntry.prototype)) {
      Object.defineProperty(window.IntersectionObserverEntry.prototype, 'isIntersecting', {
        get() {
          return this.intersectionRatio > 0
        },
      })
    }
    return true
  }
  return false
}
function assignSymbols(target, ...args) {
  if (!isObject$2(target)) {
    throw new TypeError('expected the first argument to be an object')
  }
  if (args.length === 0 || typeof Symbol !== 'function' || typeof getSymbols !== 'function') {
    return target
  }
  for (const arg of args) {
    const names = getSymbols(arg)
    for (const key of names) {
      if (isEnumerable.call(arg, key)) {
        target[key] = arg[key]
      }
    }
  }
  return target
}
function assign(target, ...args) {
  let i = 0
  if (isPrimitive(target)) target = args[i++]
  if (!target) target = {}
  for (; i < args.length; i++) {
    if (isObject$2(args[i])) {
      for (const key of Object.keys(args[i])) {
        if (isValidKey(key)) {
          if (isObject$2(target[key]) && isObject$2(args[i][key])) {
            assign(target[key], args[i][key])
          } else {
            target[key] = args[i][key]
          }
        }
      }
      assignSymbols(target, args[i])
    }
  }
  return target
}
const api = ({ images = [], options }) => {
  options = assign(options, {
    inline: false,
  })
  const token = document.createElement('div')
  const ViewerToken = h(
    'div',
    {
      style: {
        display: 'none',
      },
      class: ['__viewer-token'],
    },
    images.map((attr) => {
      return h('img', typeof attr === 'string' ? { src: attr } : attr)
    })
  )
  render(ViewerToken, token)
  const tokenElement = token.firstElementChild
  document.body.appendChild(tokenElement)
  const $viewerJs = new Viewer(tokenElement, options)
  const $destroy = $viewerJs.destroy.bind($viewerJs)
  $viewerJs.destroy = function () {
    $destroy()
    render(null, token)
    return $viewerJs
  }
  $viewerJs.show()
  tokenElement.addEventListener('hidden', function () {
    if (this.viewer === $viewerJs) {
      $viewerJs.destroy()
    }
  })
  return $viewerJs
}
var root = _root
var now$1 = function () {
  return root.Date.now()
}
var now_1 = now$1
var reWhitespace = /\s/
function trimmedEndIndex$1(string) {
  var index2 = string.length
  while (index2-- && reWhitespace.test(string.charAt(index2))) {}
  return index2
}
var _trimmedEndIndex = trimmedEndIndex$1
var trimmedEndIndex = _trimmedEndIndex
var reTrimStart = /^\s+/
function baseTrim$1(string) {
  return string ? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '') : string
}
var _baseTrim = baseTrim$1
var baseGetTag = _baseGetTag,
  isObjectLike = isObjectLike_1
var symbolTag = '[object Symbol]'
function isSymbol$1(value) {
  return typeof value == 'symbol' || (isObjectLike(value) && baseGetTag(value) == symbolTag)
}
var isSymbol_1 = isSymbol$1
var baseTrim = _baseTrim,
  isObject$1 = isObject_1,
  isSymbol = isSymbol_1
var NAN = 0 / 0
var reIsBadHex = /^[-+]0x[0-9a-f]+$/i
var reIsBinary = /^0b[01]+$/i
var reIsOctal = /^0o[0-7]+$/i
var freeParseInt = parseInt
function toNumber$1(value) {
  if (typeof value == 'number') {
    return value
  }
  if (isSymbol(value)) {
    return NAN
  }
  if (isObject$1(value)) {
    var other = typeof value.valueOf == 'function' ? value.valueOf() : value
    value = isObject$1(other) ? other + '' : other
  }
  if (typeof value != 'string') {
    return value === 0 ? value : +value
  }
  value = baseTrim(value)
  var isBinary = reIsBinary.test(value)
  return isBinary || reIsOctal.test(value)
    ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
    : reIsBadHex.test(value)
    ? NAN
    : +value
}
var toNumber_1 = toNumber$1
var isObject = isObject_1,
  now = now_1,
  toNumber = toNumber_1
var FUNC_ERROR_TEXT = 'Expected a function'
var nativeMax = Math.max,
  nativeMin = Math.min
function debounce(func, wait, options) {
  var lastArgs,
    lastThis,
    maxWait,
    result,
    timerId,
    lastCallTime,
    lastInvokeTime = 0,
    leading = false,
    maxing = false,
    trailing = true
  if (typeof func != 'function') {
    throw new TypeError(FUNC_ERROR_TEXT)
  }
  wait = toNumber(wait) || 0
  if (isObject(options)) {
    leading = !!options.leading
    maxing = 'maxWait' in options
    maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait
    trailing = 'trailing' in options ? !!options.trailing : trailing
  }
  function invokeFunc(time) {
    var args = lastArgs,
      thisArg = lastThis
    lastArgs = lastThis = void 0
    lastInvokeTime = time
    result = func.apply(thisArg, args)
    return result
  }
  function leadingEdge(time) {
    lastInvokeTime = time
    timerId = setTimeout(timerExpired, wait)
    return leading ? invokeFunc(time) : result
  }
  function remainingWait(time) {
    var timeSinceLastCall = time - lastCallTime,
      timeSinceLastInvoke = time - lastInvokeTime,
      timeWaiting = wait - timeSinceLastCall
    return maxing ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting
  }
  function shouldInvoke(time) {
    var timeSinceLastCall = time - lastCallTime,
      timeSinceLastInvoke = time - lastInvokeTime
    return (
      lastCallTime === void 0 ||
      timeSinceLastCall >= wait ||
      timeSinceLastCall < 0 ||
      (maxing && timeSinceLastInvoke >= maxWait)
    )
  }
  function timerExpired() {
    var time = now()
    if (shouldInvoke(time)) {
      return trailingEdge(time)
    }
    timerId = setTimeout(timerExpired, remainingWait(time))
  }
  function trailingEdge(time) {
    timerId = void 0
    if (trailing && lastArgs) {
      return invokeFunc(time)
    }
    lastArgs = lastThis = void 0
    return result
  }
  function cancel() {
    if (timerId !== void 0) {
      clearTimeout(timerId)
    }
    lastInvokeTime = 0
    lastArgs = lastCallTime = lastThis = timerId = void 0
  }
  function flush() {
    return timerId === void 0 ? result : trailingEdge(now())
  }
  function debounced() {
    var time = now(),
      isInvoking = shouldInvoke(time)
    lastArgs = arguments
    lastThis = this
    lastCallTime = time
    if (isInvoking) {
      if (timerId === void 0) {
        return leadingEdge(lastCallTime)
      }
      if (maxing) {
        clearTimeout(timerId)
        timerId = setTimeout(timerExpired, wait)
        return invokeFunc(lastCallTime)
      }
    }
    if (timerId === void 0) {
      timerId = setTimeout(timerExpired, wait)
    }
    return result
  }
  debounced.cancel = cancel
  debounced.flush = flush
  return debounced
}
var debounce_1 = debounce
const directive = ({ name = 'viewer', debug = false } = {}) => {
  async function createViewer(el, options, rebuild = false, observer = false) {
    await nextTick()
    if (observer && !imageDiff(el)) return
    if (rebuild || !el[`$${name}`]) {
      destroyViewer(el)
      el[`$${name}`] = new Viewer(el, options)
      log('Viewer created')
    } else {
      el[`$${name}`].update()
      log('Viewer updated')
    }
  }
  function imageDiff(el) {
    const imageContent = el.innerHTML.match(/<img([\w\W]+?)[\\/]?>/g)
    const viewerImageText = imageContent ? imageContent.join('') : void 0
    if (el.__viewerImageDiffCache === viewerImageText) {
      log('Element change detected, but image(s) has not changed')
      return false
    } else {
      log('Image change detected')
      el.__viewerImageDiffCache = viewerImageText
      return true
    }
  }
  function createObserver(el, options, debouncedCreateViewer, rebuild) {
    destroyObserver(el)
    const MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver
    if (!MutationObserver) {
      log('Observer not supported')
      return
    }
    const observer = new MutationObserver((mutations) => {
      mutations.forEach((mutation) => {
        log(`Viewer mutation:${mutation.type}`)
        debouncedCreateViewer(el, options, rebuild, true)
      })
    })
    const config = { attributes: true, childList: true, characterData: true, subtree: true }
    observer.observe(el, config)
    el.__viewerMutationObserver = observer
    log('Observer created')
  }
  function createWatcher(el, binding, vnode, debouncedCreateViewer) {
    el.__viewerUnwatch = watch(
      () => binding.value,
      (newVal, oldVal) => {
        log('Change detected by watcher: ', binding.value)
        debouncedCreateViewer(el, newVal, true, false)
      },
      { deep: true }
    )
    log('Watcher created, expression: ', binding.value)
  }
  function destroyViewer(el) {
    if (!el[`$${name}`]) {
      return
    }
    el[`$${name}`].destroy()
    delete el[`$${name}`]
    log('Viewer destroyed')
  }
  function destroyObserver(el) {
    if (!el.__viewerMutationObserver) {
      return
    }
    el.__viewerMutationObserver.disconnect()
    delete el.__viewerMutationObserver
    log('observer destroyed')
  }
  function destroyWatcher(el) {
    if (!el.__viewerUnwatch) {
      return
    }
    el.__viewerUnwatch()
    delete el.__viewerUnwatch
    log('Watcher destroyed')
  }
  function log(...args) {
    debug && console.log(...args)
  }
  const directive2 = {
    mounted(el, binding, vnode) {
      log('Viewer bind')
      const debouncedCreateViewer = debounce_1(createViewer, 50)
      debouncedCreateViewer(el, binding.value)
      createWatcher(el, binding, vnode, debouncedCreateViewer)
      if (!binding.modifiers.static) {
        createObserver(el, binding.value, debouncedCreateViewer, binding.modifiers.rebuild)
      }
    },
    getSSRProps(binding) {
      // 服务端实现：
      // 返回需要渲染的 prop
      // getSSRProps 只接收一个 binding 参数
      return {
        id: binding.value,
      }
    },
    unmounted(el) {
      log('Viewer unbind')
      destroyObserver(el)
      destroyWatcher(el)
      destroyViewer(el)
    },
  }
  return directive2
}
var _export_sfc = (sfc, props) => {
  const target = sfc.__vccOpts || sfc
  for (const [key, val] of props) {
    target[key] = val
  }
  return target
}
const _sfc_main = defineComponent({
  name: 'Viewer',
  props: {
    images: {
      type: Array,
      default: () => [],
    },
    rebuild: {
      type: Boolean,
      default: false,
    },
    trigger: {
      type: Object,
      default: null,
    },
    options: {
      type: Object,
      default: () => null,
    },
  },
  emits: ['inited'],
  setup(props, { emit }) {
    let $viewer
    const root2 = ref()
    function createViewer() {
      $viewer = new Viewer(root2.value, props.options)
      emit('inited', $viewer)
    }
    function destroyViewer() {
      $viewer && $viewer.destroy()
    }
    function rebuildViewer() {
      destroyViewer()
      createViewer()
    }
    function updateViewer() {
      if ($viewer) {
        $viewer.update()
        emit('inited', $viewer)
      } else {
        createViewer()
      }
    }
    function changeViewer() {
      if (props.rebuild) {
        rebuildViewer()
      } else {
        updateViewer()
      }
    }
    const options = { deep: true }
    watch(
      () => props.images,
      () => nextTick(() => changeViewer()),
      options
    )
    watch(
      () => props.trigger,
      () => nextTick(() => changeViewer()),
      options
    )
    watch(
      () => props.options,
      () => nextTick(() => rebuildViewer()),
      options
    )
    onMounted(() => createViewer())
    onUnmounted(() => destroyViewer())
    return {
      root: root2,
      createViewer,
      rebuildViewer,
      updateViewer,
      destroyViewer,
    }
  },
})
const _hoisted_1 = { ref: 'root' }
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return (
    openBlock(),
    createElementBlock(
      'div',
      _hoisted_1,
      [
        renderSlot(_ctx.$slots, 'default', {
          images: _ctx.images,
          options: _ctx.options,
        }),
      ],
      512
    )
  )
}
var component = /* @__PURE__ */ _export_sfc(_sfc_main, [['render', _sfc_render]])
var index = {
  install(app, { name = 'viewer', debug = false, defaultOptions } = {}) {
    if (defaultOptions) {
      Viewer.setDefaults(defaultOptions)
    }
    app.config.globalProperties[`$${name}Api`] = api
    app.component(name, defaults_1(component, { name }))
    app.directive(name, directive({ name, debug }))
  },
  setDefaults(defaultOptions) {
    Viewer.setDefaults(defaultOptions)
  },
}
export { api, component, index as default, directive }
